//
//  CYDiscoverCell.m
//  cyjf
//
//  Created by tauCross on 2017/11/28.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYDiscoverCell.h"

#import <UIImageView+WebCache.h>



@implementation CYDiscoverCellObject

@end



@interface CYDiscoverCell ()

@property(nonatomic, strong)UIImageView *activityImageView;
@property(nonatomic, strong)UIView *activityMaskView;
@property(nonatomic, strong)UIImageView *statusImageView;

@end


@implementation CYDiscoverCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.activityImageView = [[UIImageView alloc] init];
        self.activityImageView.layer.masksToBounds = YES;
        self.activityImageView.layer.cornerRadius = 5;
        self.activityImageView.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:self.activityImageView];
        
        self.activityMaskView = [[UIImageView alloc] init];
        self.activityMaskView.backgroundColor = HEXCOLORA(@"000000", 0.5);
        [self.activityImageView addSubview:self.activityMaskView];
        
        self.statusImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 90, 90)];
        [self.activityMaskView addSubview:self.statusImageView];
    }
    return self;
}

+ (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return 20 + (SCREEN_WIDTH - 40) * 150 / 335;
}

- (BOOL)shouldUpdateCellWithObject:(CYDiscoverCellObject *)object
{
    [self.activityImageView sd_setImageWithURL:object.model.image.tc_url placeholderImage:CYImage(@"find_banner_empty")];
    self.activityMaskView.hidden = object.model.range.integerValue == 1;
    if(object.model.range.integerValue == 2)
    {
        self.statusImageView.image = CYImage(@"tag_tobegin");
    }
    else
    {
        self.statusImageView.image = CYImage(@"tag_overtime");
    }
    
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.activityImageView.width = self.contentView.width - 40;
    self.activityImageView.height = self.contentView.height - 20;
    self.activityImageView.centerX = self.contentView.width / 2;
    self.activityImageView.centerY = self.contentView.height / 2;
    
    self.activityMaskView.frame = self.activityImageView.bounds;
    
    self.statusImageView.bottom = self.activityMaskView.height;
    self.statusImageView.right = self.activityMaskView.width - 10;
}

@end
